import jwt
import time


class JWTON:
    def __init__(self):
        self.secrite_key = '%#@%#$$^$#!@@#R@#FECDASCVWVRWq">:>:L(OLOP*$#'

    # 生成jwt
    def jwt_en(self, data):
        return jwt.encode(data, self.secrite_key, algorithm='HS256')

    # 对比
    def jwt_check(self, token):
        try:
            data = jwt.decode(token, self.secrite_key, algorithms='HS256')
            newtoken = str(jwt.encode(data, self.secrite_key, algorithm='HS256'))
            if token == newtoken:
                print(True)
                return True
        except:
            return False

    # 解密
    def jwt_de(self,token):
        try:
            payload = jwt.decode(token,self.secrite_key,algorithms='HS256')
            return payload
        except:
            return None



jwte = JWTON()